package com.douqu.game.core.util;

import com.douqu.game.core.factory.ConstantFactory;

import java.util.List;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2018-01-28 14:48
 */
public class StringUtils {

    public static String appendObject(Object... objects)
    {
        return appendParam("", objects);
    }

    public static String appendParam(String key, Object... objects)
    {
        if(objects.length == 0)
            return "";

        StringBuilder builder = new StringBuilder();
        for(Object obj : objects)
        {
            if(obj instanceof Object[])
                builder.append(appendParam(key, (Object[])obj)).append(key);
            else if(obj instanceof List)
                builder.append(appendParam(key, ((List) obj).toArray())).append(key);
            else
                builder.append(obj).append(key);
        }
        return builder.substring(0, builder.length() - key.length());
    }

    public static boolean isNullOrEmpty(String value)
    {
        return value == null || value.length() == 0 || value.replace(" ", "").length() == 0;
    }


    public static int[] toIntArray(String value)
    {
        int[] result = null;
        try{
            String[] strs = value.split(ConstantFactory.COMMA);
            result = new int[strs.length];
            int i = 0;
            for(String v : strs)
            {
                result[i++] = Integer.parseInt(v);
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return result;
    }
}
